home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2005 June
/
ccd0605.iso
/
Software
/
Freeware
/
Programare
/
highlight
/
highlight-W32GUI-2.2-10b-Setup.exe
/
{app}
/
src
/
texgenerator.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
2005-03-31
|
7KB
|
287 lines
/***************************************************************************
TexGenerator.cpp - description
-------------------
begin : Mit Jul 24 2002
copyright : (C) 2002 by AndrΘ Simon
email : andre.simon1@gmx.de
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "texgenerator.h"
namespace highlight {
TexGenerator::TexGenerator(const string &colourTheme):
CodeGenerator( colourTheme)
{
styleTagOpen.push_back( "{\\hlstd ");
styleTagOpen.push_back( "{\\hlstr ");
styleTagOpen.push_back( "{\\hlnum ");
styleTagOpen.push_back( "{\\hlslc ");
styleTagOpen.push_back( "{\\hlcom ");
styleTagOpen.push_back( "{\\hlesc ");
styleTagOpen.push_back( "{\\hldir ");
styleTagOpen.push_back( "{\\hldstr ");
styleTagOpen.push_back( "{\\hlline ");
styleTagOpen.push_back( "{\\hlsym ");
for (int i=0;i<NUMBER_BUILTIN_STYLES; i++) {
styleTagClose.push_back( "}");
}
/*This makes TeX to use every par it encounters (the \\leavevmode has
no effect when TeX is in horizontal mode and when TeX is in vertical
mode, it switches it to horizontal mode).*/
newLineTag="\\leavevmode\\par\n";
spacer = "\\ ";
maskWs=true;
excludeWs=true;
maskWsBegin = "{\\hlstd";
maskWsEnd = "}";
styleCommentOpen="%";
}
TexGenerator::TexGenerator()
{}
TexGenerator::~TexGenerator()
{}
string TexGenerator::formatStyleAttributes(const string & elemName,const ElementStyle & elem)
{
ostringstream s;
s << "\\def\\hl"
<< elemName
<< "{";
if (elem.isBold())
s << "\\bf";
if (elem.isItalic())
s << "\\it";
s << "\\textColor{"
<< (elem.getColour().getTexRedValue())<<" "
<< (elem.getColour().getTexGreenValue())<<" "
<< (elem.getColour().getTexBlueValue())<<" 0.0}}\n";
return s.str();
}
string TexGenerator::getHeader(const string & title)
{
ostringstream os;
if (langInfo.getSyntaxHighlight()) {
if (includeStyleDef) {
os << "\n"<<getStyleDefinition();
os << CodeGenerator::readUserStyleDef();
} else {
os << "\\input "
<< getStyleOutputPath()
<< "\n\n";
}
}
return os.str();
}
void TexGenerator::printBody()
{
*out << "{\n\\tt\n";
processRootState();
*out << "}\n";
}
string TexGenerator::getFooter()
{
ostringstream os;
os << "\\bye\n"
<< "% TeX generated by Highlight "
<< HIGHLIGHT_VERSION
<< ", "
<< HIGHLIGHT_URL
<< endl;
return os.str();
}
string TexGenerator:: maskCharacter(unsigned char c)
{
switch (c)
{
case '{':
case '}':
{
string m;
m = "$\\";
m += c;
m += "$";
return m;
}
break;
case '^':
return "{\\bf\\^{}}";
break;
case '_':
return "\\_{}";
break;
case '&':
case '$':
case '#':
case '%':
{
string m;
m = "\\";
m += c;
return m;
}
break;
case '\\':
return "$\\backslash$";
break;
case ' ':
return spacer;
break;
case '+':
case '-':
case '<':
case '>':
case '=':
{
string m;
m = "$\\mathord{";
m += c;
m += "}$";
return m;
}
break;
case AUML_LC:
return "\\\"a";
break;
case OUML_LC:
return "\\\"o";
break;
case UUML_LC:
return "\\\"u";
break;
case AUML_UC:
return "\\\"A";
break;
case OUML_UC:
return "\\\"O";
break;
case UUML_UC:
return "\\\"U";
break;
case AACUTE_LC:
return "\\'a";
break;
case EACUTE_LC:
return "\\'e";
break;
case OACUTE_LC:
return "\\'o";
break;
case UACUTE_LC:
return "\\'u";
break;
case AGRAVE_LC:
return "\\`a";
break;
case EGRAVE_LC:
return "\\`e";
break;
case OGRAVE_LC:
return "\\`o";
break;
case UGRAVE_LC:
return "\\`u";
break;
case AACUTE_UC:
return "\\'A";
break;
case EACUTE_UC:
return "\\'E";
break;
case OACUTE_UC:
return "\\'O";
break;
case UACUTE_UC:
return "\\'U";
break;
case AGRAVE_UC:
return "\\`A";
break;
case EGRAVE_UC:
return "\\`E";
break;
case UGRAVE_UC:
return "\\`O";
break;
case OGRAVE_UC:
return "\\`U";
break;
case SZLIG:
return "\\ss ";
break;
/* #ifndef _WIN32
// skip first byte of multibyte chracters
case 195:
return string("");
break;
#endif*/
default :
string m;
return m += c;
}
}
string TexGenerator::getMatchingOpenTag(unsigned int styleID){
return "{\\hl"+langInfo.getKeywordClasses()[styleID]+" ";
}
string TexGenerator::getMatchingCloseTag(unsigned int styleID){
return "}";
}
string TexGenerator::getStyleDefinition()
{
if (styleDefinitionCache.empty()){
ostringstream os;
os << formatStyleAttributes("std", docStyle.getDefaultStyle());
os << formatStyleAttributes("num", docStyle.getNumberStyle());
os << formatStyleAttributes("esc", docStyle.getEscapeCharStyle());
os << formatStyleAttributes("str", docStyle.getStringStyle());
os << formatStyleAttributes("dstr", docStyle.getDirectiveStringStyle());
os << formatStyleAttributes("slc", docStyle.getSingleLineCommentStyle());
os << formatStyleAttributes("com", docStyle.getCommentStyle());
os << formatStyleAttributes("dir", docStyle.getDirectiveStyle());
os << formatStyleAttributes("line", docStyle.getLineStyle());
os << formatStyleAttributes("sym", docStyle.getSymbolStyle());
KeywordStyles styles = docStyle.getKeywordStyles();
for (KSIterator it=styles.begin(); it!=styles.end(); it++){
os << formatStyleAttributes(it->first, *(it->second));
}
os << "% The special option is not supported by all dvi drivers\n"
<< "\\special{background rgb "
<< docStyle.getBgColour().getLatexRedValue() << " "
<< docStyle.getBgColour().getLatexGreenValue() << " "
<< docStyle.getBgColour().getLatexBlueValue() << "}";
os << "\n\\nopagenumbers\n"
<< "\\input colordvi\n";
styleDefinitionCache=os.str();
}
return styleDefinitionCache;
}
}